﻿package src.game{
	import flash.display.Sprite;
	import flash.display.MovieClip;

	public class Paddle extends Sprite{
		public static const ORIENTATNION_HORIZONTAL:String = "Horizontal";
		public static const ORIENTATNION_VERTICAL:String = "Vertical";
		
		private var orientation:String;
		private var left:MovieClip;
		private var right:MovieClip;
		private var center:MovieClip;
		
		private var minRange:int;
		private var maxRange:int;
		
		public function Paddle(orientation:String) {
			if (orientation==ORIENTATNION_HORIZONTAL || orientation==ORIENTATNION_VERTICAL)
				this.orientation = orientation;
			init();
		}
		
		private function init():void {
			left = new PaddleMc();
			left.gotoAndStop(1);
			center = new PaddleMc();
			center.gotoAndStop(2);
			right = new PaddleMc();
			right.gotoAndStop(3);
			this.addChild(left);
			this.addChild(center);
			this.addChild(right);
			
			if (orientation == ORIENTATNION_VERTICAL) {
				left.rotation = 90;
				center.rotation = 90;
				right.rotation = 90;
				center.y = left.height;
				right.y = center.y + center.height;
			}
			else if (orientation == ORIENTATNION_HORIZONTAL) {
				center.x = left.width;
				right.x = center.x + center.width;
			}
		}
		
		public function setSize(width:int) {
			width = Math.max(0, width - (left.width + right.width) );
			if (orientation == ORIENTATNION_HORIZONTAL) {
				center.width = width;
				right.x = center.x + width;
			}
			else if (orientation == ORIENTATNION_VERTICAL) {
				center.width = width;
				right.y = center.y + width;
			}
		}
		
		public function getWidth():int {
			return this.width;
		}
		
		public function getHeight():int {
			return this.height;
		}
		
		public function moveTo(x:int, y:int):void {
			if (orientation == ORIENTATNION_HORIZONTAL)
				this.x = x - this.width/2;
			else if (orientation == ORIENTATNION_VERTICAL)
				this.y = y - this.height/2;;
		}
		
		public function getX():int {
			return (this.x + this.width/2);
		}
		
		public function getY():int {
			return (this.y + this.height/2);
		}
		
		public function getOrientation():String {
			return this.orientation;
		}
		
		public function setMinRange(r:int):void {
			minRange = r;
		}
		
		public function setMaxRange(r:int):void {
			maxRange = r;
		}
		
		public function getMinRange():int {
			return minRange;
		}
		
		public function getMaxRange():int {
			return maxRange;
		}
	}
}
